// miniprogram/pages/home_center/device_list/index.js.js
require('regenerator-runtime');
import { getDeviceList } from '@ray-js/wechat';

Page({
  /**
   * 页面的初始数据
   */
  data: {
    active: 0,
    deviceList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    const deviceList = await getDeviceList();
    this.setData({ deviceList });
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  jumpToPanel({ currentTarget }) {
    const {
      dataset: { device },
    } = currentTarget;
    const { id, category, name } = device;
    switch (category) {
      default: {
        wx.navigateTo({
          url: `/packageA/home_center/common_panel/index?device_id=${id}&device_name=${name}`,
        });
      }
    }
  },
});
